package linke.study.spring.service.aspect;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class ValidationAspect {

	Log log = LogFactory.getLog(ValidationAspect.class);

//	@Pointcut("execution(public linke.study.spring.service.SecurityService.doUserLogin(..) &&" +
//			"args(username,password)")
//	private void beforeUserLogin(String username, String password) {}
//	@Before("beforeUserLogin(userName,password)")
//	public void checkLoginInfoNotNull(String username, String password) {
//	if (username.contains("--") || password.contains("--")) {
//		throw new IllegalArgumentException("用户名或者密码含非法字符");
//	}
//	}
	
	@Before("execution(public * linke.study.spring.service.SecurityService.doUserLogin(..)) &&" +
			" args(username,password)")
	public void beforeUserLogin(JoinPoint joinPoint, String username, String password) {
		log.info("checking arguments of: " + joinPoint.getSignature() + ", they can't be null");
		if(username == null || password == null) {
			throw new IllegalArgumentException("用户名或者密码为空");
		}
	}
}
